import request from '@/utils/request'
import type { Role, RoleListData, RoleParams } from './model/role'

// 角色列表分页查询
export const getRoleList = async (data: RoleParams) => {
  return await request.post<RoleListData>('/system/role/loadList', {
    data
  })
}

// 角色列表下拉框

export const getRoleOptionList = async () => {
  return await request.get('/system/role/optionSelect')
}

// 获取所有菜单树

export const getMenu = async () => {
  return await request.get('/system/menu/treeSelect')
}

// 新增角色

export const addRole = async (data: Role) => {
  return await request.post('/system/role/add', { data })
}

// 删除角色
export const removeRole = async (data: Role) => {
  const userIds = data.roleId ?? ''
  return await request.delete(`/system/role/${userIds}`)
}

// 编辑角色
export const editRole = async (data: Role) => {
  return await request.put('/system/role/edit', {
    data
  })
}

// 角色路由
export const getRouters = async () => {
  return await request.get('/system/menu/getRouters')
}
